r=$(date +%Y)
current_month=$(date +%m)
current_day=$(date +%d)

ls /opt/log/ | while read line; do
    file_year=$(echo $line | awk -F. '{print $1}' | awk -F- '{print $2}')
    file_month=$(echo $line | awk -F. '{print $1}' | awk -F- '{print $3}')
    file_day=$(echo $line | awk -F. '{print $1}' | awk -F- '{print $4}')

    file_year=${file_year#0}
    file_month=${file_month#0}
    file_day=${file_day#0}

    if [ "$current_year" -eq "$file_year" ] && [ "$current_month" -eq "$file_month" ] && [ "$current_day" -gt "$file_day" ] && [ $(($current_day - $file_day)) -gt 3 ]; then
        rm -f "/opt/log/$line"
        echo "文件$line已经超过3天,已被删除"
    fi
done
